package servicesImp.expertInfo;


import StaticFinal.CrudType;
import base.IBaseMapperWithoutBLOBs;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import services.expertInfo.ExpertBaseServices;
import services.expertInfo.LeaderCheckServices;
import util.key.IDFactory;
import wt.dao.expertInfo.ExpertBaseMapper;
import wt.entity.expertInfo.ExpertBase;
import wt.entity.expertInfo.ExpertBaseExample;
import wt.entity.expertInfo.LeaderCheckWithBLOBs;
import wt.staticData.TableName;

import java.util.List;

/**
 * Created by Administrator on 2017/10/14.
 */
@Service
public class ExpertBaseExpertInfoServicesImp extends BaseExpertInfoServicesImp<ExpertBase, ExpertBaseExample> implements ExpertBaseServices {
    @Autowired
    ExpertBaseMapper expertBaseMapper;
    @Autowired
    LeaderCheckServices leaderCheckServices;

    @Override
    public IBaseMapperWithoutBLOBs<ExpertBase, ExpertBaseExample> getMapper() {
        return this.expertBaseMapper;
    }

    @Override
    public String getTableName() {
        return TableName.EMS_EXPERT_BASE;
    }


    @Override
    public ExpertBase getEntity() {
        return new ExpertBase();
    }

    @Override
    public ExpertBaseExample getRecordExample() {
        return new ExpertBaseExample();
    }

    @Override
    public LeaderCheckServices getLeaderCheckServices() {
        return leaderCheckServices;
    }

    @Override
    public ExpertBaseServices getExpertBaseServices() {
        return this;
    }

//    @Override
//    public int expertCancelApplyByPrimaryKey(String id) throws Exception {
//        ExpertBase temp = new ExpertBase();
//        temp.setId(id);
//        temp.setCrudType(CrudType.select);
//        temp.setCrudData("");
//        return getCurrentProxy().updateByPrimaryKeySelective(temp);
//    }

//    @Override
//    @Transactional
//    public void adminInsertSelective(Record record) throws Exception {
//        record.setCrudType(CrudType.select);
//        record.setCrudData("");
//
//        ExpertBase expertBase = getExpertBaseServices().selectByPrimaryKey(record.getExpertId());
//        recordProcess(record);
//        LeaderCheckWithBLOBs blobs = LeaderCheckUtil.verifier1Insert(record, getTableName(), expertBase);
//        getCurrentProxy().insertSelective(record);
//        getLeaderCheckServices().insertSelective(blobs);
//    }


    @Transactional
    @Override
    public void adminInsertSelective(ExpertBase expertBase) throws Exception {

        expertBase.setId(IDFactory.getSnowflakeId());
        expertBase.setCrudType(CrudType.select);
        expertBase.setCrudData("");

        recordProcess(expertBase);
        LeaderCheckWithBLOBs blobs = LeaderCheckUtil.verifier1Insert(expertBase, getTableName(), expertBase);
        getCurrentProxy().insertSelective(expertBase);
        getLeaderCheckServices().insertSelective(blobs);
    }

    public ExpertBase selectByIdCard(String idCard) throws Exception {
        ExpertBaseExample expertBaseExample = new ExpertBaseExample();
        expertBaseExample.createCriteria().andIdCardEqualTo(idCard);
        List<ExpertBase> expertBaseList = selectByExample(expertBaseExample);

        if (expertBaseList.isEmpty()) {
            return null;
        } else {
            return expertBaseList.get(0);
        }
    }

    public List<ExpertBase> selectByIdCard(List<String> idCardList) throws Exception {
        ExpertBaseExample expertBaseExample = new ExpertBaseExample();
        expertBaseExample.createCriteria().andIdCardIn(idCardList);
        return selectByExample(expertBaseExample);
    }

    //=================================================================================================

    @Deprecated
    @Override
    public boolean isExistUnauditedRecord(String expertId) throws Exception {
        return super.isExistUnauditedRecord(expertId);
    }

    @Deprecated
    @Override
    public List<ExpertBase> adminSelectByExpertId(String expertId) throws Exception {
        return super.adminSelectByExpertId(expertId);
    }

    @Deprecated
    @Override
    public void adminDeleteByPrimaryKey(String id) throws Exception {
        super.adminDeleteByPrimaryKey(id);
    }

    @Deprecated
    @Override
    public List<ExpertBase> expertSelectByExpertId(String expertId) throws Exception {
        return super.expertSelectByExpertId(expertId);
    }

    @Deprecated
    @Override
    public void expertDeleteByPrimaryKey(String id) throws Exception {
        super.expertDeleteByPrimaryKey(id);
    }

    @Deprecated
    @Override
    public void expertInsertSelective(ExpertBase expertBase) throws Exception {
        super.expertInsertSelective(expertBase);
    }


}
